package com.kisszpy.core;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.kisszpy.system.entity.SysUser;
import com.kisszpy.system.exceptions.NotLoginException;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class AccessIntercepter implements Interceptor {

	private static final long serialVersionUID = -8104413171634208748L;

	public void destroy() {
		// TODO Auto-generated method stub
		
	}
	private List<String> list = new ArrayList<String>();
	public void init() {
		list.add("SysUser!renderCode.do");
		list.add("SysUser!login.do");
	}
	
	public String intercept(ActionInvocation invocation) throws Exception {
		 /*SysUser login_key = (SysUser) ServletActionContext.getRequest().getSession().getAttribute("login_key");
		 String uri = ServletActionContext.getRequest().getRequestURI();
		 System.out.println(uri);
		 boolean flag = false;
		 for(int i = 0;i<list.size();i++){
			 if(uri.contains(list.get(i))){
				 flag = true;
			 }
		 }
		 if(!flag){ // 排除不需要验证的页面
			if(null==login_key){
				ServletActionContext.getRequest().setAttribute("exception_info", new NotLoginException("您没有登录！请先登录"));
				return "error";
			}
		 }*/
		 return invocation.invoke();
	}

}
